﻿var corpGuid;
var areaCode;
var empGuid;
var status;
var selAll;
var DropQual;
var DropSubQual;
var DropCardType;
var ok = 0;
var typeFlag;
var tFlag;
var model;
var editStatus;
var backUrl;
var userRole;
var roleId;
var manual;
var sysCode;
// var funcCode='';
var empUpImgExt; //安全考核证图片
var empExt; //安全考核证
var CertCodeExt; //安全考核证编号
var eduGuid; //安全考核证guid
var CloseBtn = "0"; //是否显示关闭按钮
var msg; //窗口提示
var pdfDwonUrl="";//pdf下载地址

/*绑定按钮事件*/
function BindBtnClick() {
    //人员资格
//    var title = "建设类注册执业证书";
//    $("#QualAdd").click(function () {
//       
//        ShowAddForm("../Person/PersonEmpCertInfo.aspx?title="+escape(title)+"&empGuid=" + empGuid, 810, 650);
//    });
    $("#QualEdit").click(function () {
        ShowEditForm("../Person/PersonEmpCertAmend.aspx?empGuid=" + empGuid + "&certGuid=", "EmpQualities", 650, 450);
    });
//    $("#QualDel").click(function () {
//        EmpDel("QualitieDel", "EmpQualities");
//    });
    //身份证
    $("#txtCard").blur(function () {
        IDCardCheck();
    });
    ////导出pdf
    $("#btnDownPdf").click(function () {
        GetTel();
        GetEmail();
        var dataValid = CheckControlValid("SaveEmpInfo");
        if (!dataValid) {
            return false;
        }
        window.open("../Handlers/PdfDownHandler.ashx?empGuid=" + empGuid);
    });
    //工作经历
    $("#WorkAdd").click(function () {
        ShowAddForm("../Person/PersonEmpWorkInfo.aspx?empGuid=" + empGuid + "&corpName=" +escape($("#txtCorpName").val()), 800, 400);
    });
    $("#WorkEdit").click(function () {
        ShowEditForm("../Person/PersonEmpWorkInfo.aspx?empGuid=" + empGuid + "&corpName=" + escape($("#txtCorpName").val()) + "&workId=", "EmpWork", 800, 400);
    });
    $("#WorkDel").click(function () {
        EmpWorkDel("ExperienceDel", "EmpWork");
    });
    //专家专业
    $("#ExpSpecAddMain").click(function () {
        ShowAddForm("../Person/PersonExpSpecialityInfo.aspx?empGuid=" + empGuid + "&isMain=true", 900, 600);
    });
    $("#ExpSpecAddEtc").click(function () {
        ShowAddForm("../Person/PersonExpSpecialityInfo.aspx?empGuid=" + empGuid + "&isMain=false", 870, 600);
    });
    $("#ExpSpecAddEtc2").click(function () {
        ShowAddForm("../Person/PersonExpSpecialityInfo.aspx?empGuid=" + empGuid + "&isMain=false", 900, 600);
    });
    $("#ExpSpecEditMain").click(function () {
        ShowEditForm("../Person/PersonExpSpecialityInfo.aspx?empGuid=" + empGuid + "&isMain=true&specGuid=", "ExpSpecMain", 900, 600);
    });
    $("#ExpSpecEditEtc").click(function () {
        ShowEditForm("../Person/PersonExpSpecialityInfo.aspx?empGuid=" + empGuid + "&isMain=false&specGuid=", "ExpSpecEtc", 900, 600);
    });
    $("#ExpSpecEditEtc2").click(function () {
        ShowEditForm("../Person/PersonExpSpecialityInfo.aspx?empGuid=" + empGuid + "&isMain=false&specGuid=", "ExpSpecEtc2", 900, 600);
    });
    $("#ExpSpecDelMain").click(function () {
        ExpertSpecialityDel("SpecDel", "ExpSpecMain");
    });
    $("#ExpSpecDelEtc").click(function () {
        ExpertSpecialityDel("SpecDel", "ExpSpecEtc");
    });
    $("#ExpSpecDelEtc2").click(function () {
        ExpertSpecialityDel("SpecDel", "ExpSpecEtc2");
    });
    //专家关系
    $("#CorpRelAdd").click(function () {
        ShowAddForm("../Enterprise/EnterpriseInput.aspx?empGuid=" + empGuid + "&Flag=1", 1000, 800);
    });
    $("#CorpRelEdit").click(function () {
        ShowEditForm("../Enterprise/EnterpriseInput.aspx?empGuid=" + empGuid + "&Flag=1&Gid=", "CorpRelBody", 1000, 800);
    });
    $("#ExpRelAdd").click(function () {
        ShowAddForm("../Person/PersonExpertSelect.aspx?empGuid=" + empGuid + "&Flag=0", 1000, 800);
    });
    $("#ExpRelEdit").click(function () {
        ShowEditForm("../Person/PersonExpertSelect.aspx?empGuid=" + empGuid + "&Flag=0&Gid=", "ExpRelBody", 1000, 800);
    });
    $("#CorpRelDel").click(function () {
        ExpertRelationDel("RelationDel", "CorpRelBody");
    });
    $("#ExpRelDel").click(function () {
        ExpertRelationDel("RelationDel", "ExpRelBody");
    });
    //保存基本信息
    $("#SaveEmpInfo").click(function () {
        EmpInfoSave("SaveEmpInfo",0);
    });
    //上传照片
    $("#imgUpload").click(function () {
        ShowUpForm("../UploadImages/PortraitUploadNotice.aspx?gettype=last&filename=" + empGuid, 700, 515);
        return false;
    });
    //职称下拉列表
    selPostAll();
    $("#" + DropQual).change(function () {
        SelChange();
    });
    //返回列表
    if (model == "0") {
        $("#btnRet").show();
        $("#btnRet").click(function () {
            window.location = "../Person/PersonEmpList.aspx?typeFlag=" + typeFlag;
        });
    } else {
        $("#btnRet").hide();
    }
    //上报
    $("#SubmitEmp").click(function () {
        EmpSubmit();
    });

    //审核
    $("#EmpAudit").click(function () {
        ShowUpForm("../Person/PersonEmpAudit.aspx?empGuid=" + empGuid + "&corpGuid=" + corpGuid + "&areaCode=" + areaCode, 820, 420);
        return false;
    });
    //显示图片预览和上传按钮
    EmpImgBtnClick();
    ToImgZoom();

    //人员手册
    var title = "建设类注册执业证书";
    $("#QualscAdd").click(function () {
        ShowAddForm("../Person/PersonEmpCertInfo.aspx?isValid=0&title=" + escape(title) + "&empGuid=" + empGuid + "&manual=" + manual, 810, 650);
    });
    $("#QualscEdit").click(function () {
        ShowEditForm("../Person/PersonEmpCertInfo.aspx?isValid=0&title=" + escape(title) + "&empGuid=" + empGuid + "&manual=" + manual + "&certGuid=", "EmpQualitiesSC", 810, 650);
    });
    $("#QualscDel").click(function () {
        EmpQualscDel("QualitieDel", "EmpQualitiesSC");
    });
//    $("#Printbtn").click(function () {
//        EmpQualscPrint("EmpQualitiesSC");
//    });
    //关闭窗口按钮事件
//    OnCloseChangeEmp();

}
/*安全生产许可证及相关项显示*/
function EmpExtShowStatus() {
    $("#" + empUpImgExt).show();
    $("#" + empExt).show();
}
/*安全生产许可证及相关项显示*/
function EmpExtHideStatus() {
    $("#" + empUpImgExt).hide();
    $("#" + empExt).hide();
}

/*打开添加窗口*/
function ShowUpForm(u, w, h, win) {
    win = win || this;
    $.ligerDialog.open({ url: u, width: w, height: h, title: '', buttons: [{ text: '关闭', onclick: function (item, dialog) { dialog.close(); } }] });
    win.ChildDialogWin = this;
    return false;
}
function ShowAddForm(u, w, h, win) {
    if (ok == 0) {
        // alert("请先添加人员基本信息！");
        OpenAlert("请先填写人员基本信息，点击【保存】按钮之后，再录入其它信息！");
        return false;
    }
    win = win || this;
    $.ligerDialog.open({ url: u, width: w, height: h, title: '', isResize: true });
    win.ChildDialogWin = this;
    return false;
}
/*打开编辑窗口*/
function ShowEditForm(u, tbodyname, w, h) {
    if (ok == 0) {
        OpenAlert("请先填写人员基本信息，点击【保存】按钮之后，再录入其它信息！");
        return false;
    }
    var keyId = GetKeyID(tbodyname);
    if (keyId == "") {
        OpenAlert("请选择操作项！");
        return false;
    }
    if (keyId.indexOf(",") > 0) {
        OpenAlert("只能选择一个操作项！");
        return false;
    }
    win = top || this;
    $.ligerDialog.open({ url: u + keyId, width: w, height: h, title: '', isResize: true });
    win.ChildDialogWin = this;
    return false;
}
///取得评审资格小项
function selPostAll() {
    $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", { "action": "PostPszg", "rand": Math.random() }, function (data) {
        selAll = data;
    });
}
///评审资格选择
function SelChange() {
    var post1 = $("#" + DropQual).val();
    $("#" + DropSubQual).empty();
    $("#" + DropSubQual).append("<option value='-1'>请选择</option>");
    if (post1 == "-1") {
        return;
    }
    if (selAll == null || selAll == "undefined") {
        return;
    }
    for (var x in selAll) {
        if (x.length <= 2) {
            continue;
        }
        if (x.substring(0, 2) == post1) {
            if (selAll[x].indexOf("会计师") != -1 || selAll[x].indexOf("审计师") != -1 || selAll[x].indexOf("统计师") != -1) {
                continue;
            }
            $("#" + DropSubQual).append("<option value='" + x + "'>" + selAll[x] + "</option>");
        }
    }
}
///验证身份证号
function IDCardCheck() {
    var IDCard = $("#txtCard").val() || "";
    var DropPost = "ContentPlaceHolder1_UCPsnExpertInfo1_DropPost";
    if (IDCard == "") {
        return false;
    }
    //验证格式
    if ($("#" + DropCardType).val() == "1") {
        if (!isIdCardNo("#txtCard")) {
            return false;
        }
    }
    var sex = 0;
    //验证性别(倒数第二位如果是奇数则是男)
    if (/[13579].$/.test(IDCard)) {
        sex = 1;
    }
    $("#ContentPlaceHolder1_UCPsnExpertInfo1_DropSex").val(sex);
    //增加人员退休定位，男60女55
    var age = CalculateAge($.trim($("#txtCard").val()));
    if ((sex == 1 && age >= 60) || (sex==0 && age>=55)) {
        $("#ContentPlaceHolder1_UCPsnExpertInfo1_DropPost").val("3");
    }
    $("#txtBirthday").val(GetBirthday($("#txtCard").val()));
}
//计算年龄
function CalculateAge(s) {
    var myDate = new Date();
    var month = myDate.getMonth() + 1;
    var day = myDate.getDate();

    var age = myDate.getFullYear() - s.substring(6, 10) - 1;
    if (s.substring(10, 12) < month || s.substring(10, 12) == month && s.substring(12, 14) <= day) {
        age++;
    }
    return age;
}

function EmpDelCheck(tbodyname) {
    if (empGuid == "") {
        OpenAlert("请先添加人员基本信息！");
        return false;
    }
    var keyId = GetKeyID(tbodyname);
    if (keyId == "") {
        OpenAlert("请选择操作项！");
        return false;
    }
    return true;
}
/*删除人员手册*/
function EmpQualscDel(action, tbodyname) {
    if (!EmpDelCheck(tbodyname)) {
        return false;
    }
    var keyId = GetKeyID(tbodyname); //取得选择项
    var entityName = GetKeyName(tbodyname);
    if (confirm("您确定要删除此信息！")) {
        $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", { "action": action, "empGuid": empGuid, "keyId": keyId, "areaCode": areaCode, "rand": Math.random() }, function (data) {
            OpenAlert(data.Message);
            GetEmpQualitiesSC();
            if (data.Result) {
                $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", { "action": "DelRelationCorp", "empGuid": empGuid, "keyId": keyId, "areaCode": areaCode, "entityName": entityName, "rand": Math.random() }, function (data) {
                    GetExpertRelation(1);
                });
            }
        });
        GetEmpUserLog(1, 10);
    }
    return false;
}

/*删除人员资格*/
function EmpDel(action, tbodyname) {
    if (empGuid == "") {
        OpenAlert("请先添加人员基本信息！");
        return false;
    }
    var keyId = GetKeyID(tbodyname); //取得选择项
    if (keyId == "") {
        OpenAlert("请选择操作项！");
        return false;
    }
    if (confirm("您确定要删除此信息！")) {
        $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", { "action": action, "empGuid": empGuid, "keyId": keyId, "areaCode": areaCode, "rand": Math.random() }, function (data) {
            OpenAlert(data.Message);
            GetEmpQualities();
        });
        GetEmpUserLog(1, 10);
    }
    return false;
}
/*删除工作经历*/
function EmpWorkDel(action, tbodyname) {
    if (empGuid == "") {
        OpenAlert("请先添加人员基本信息！");
        return false;
    }
    var keyId = GetKeyID(tbodyname);
    if (keyId == "") {
        OpenAlert("请选择操作项！");
        return false;
    }
    var entityName = GetKeyName(tbodyname);
    if (confirm("您确定要删除此信息！")) {
        $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", { "action": action, "empGuid": empGuid, "keyId": keyId, "areaCode": areaCode, "rand": Math.random() }, function (data) {
            OpenAlert(data.Message);
            GetEmpWorkExperience();
            GetEmpUserLog(1, 10);
            if (data.Result) {
                $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", { "action": "DelRelationCorp", "empGuid": empGuid, "keyId": keyId, "areaCode": areaCode,"entityName":entityName, "rand": Math.random() }, function (data) {
                    GetExpertRelation(1);
                });
            }
        });
    }
    return false;
}

/*删除专家利害关系数据*/
function ExpertRelationDel(action, tbodyname) {
    if (empGuid == "") {
        OpenAlert("请先添加人员基本信息！");
        return false;
    }
    var keyId = GetKeyID(tbodyname);
    if (keyId == "") {
        OpenAlert("请选择操作项！");
        return false;
    }
    if (keyId.indexOf(",") > 0) {
        OpenAlert("只能选择一个操作项！");
        return false;
    }
    if (confirm("您确定要删除此信息！")) {
        $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", { "action": action, "empGuid": empGuid, "Gid": keyId, "areaCode": areaCode, "rand": Math.random() }, function (data) {
            OpenAlert(data.Message);
            GetExpertRelation(1);
            GetExpertRelation(0);
        });
    }
    return false;
}

/*删除专家专业数据*/
function ExpertSpecialityDel(action, tbodyname) {
    if (empGuid == "") {
        OpenAlert("请先添加人员基本信息！");
        return false;
    }
    var keyId = GetKeyID(tbodyname);
    if (keyId == "") {
        OpenAlert("请选择操作项！");
        return false;
    }
    if (keyId.indexOf(",") > 0) {
        OpenAlert("只能选择一个操作项！");
        return false;
    }
    if (confirm("您确定要删除此信息！")) {
        $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", { "action": action, "empGuid": empGuid, "Guid": keyId, "areaCode": areaCode, "rand": Math.random() }, function (data) {
            OpenAlert(data.Message);
            GetExpertSpeciality(true);
            GetExpertSpeciality(false);
        });
    }
    return false;
}

/*取得选择的项编号*/
function GetKeyID(tbodyname) {
    var selstr = "";
    $("input[type='checkbox']:checked", $("#" + tbodyname)).each(function () {
        selstr += $(this).attr("id") + ",";
    });
    if (selstr != "") {
        selstr = selstr.substring(0, selstr.length - 1);
    }
    return selstr;
}
function GetKeyName(tbodyname,entityName) {
    var selstr = "";
    $("input[type='checkbox']:checked", $("#" + tbodyname)).each(function () {
        selstr += $(this).attr("entity") + ",";
    });
    if (selstr != "") {
        selstr = selstr.substring(0, selstr.length - 1);
    }
    return selstr;
}
//取得上传验证图片列表，固定验证身份证，添加安全考核证编号则验证安全考核证
function GetCheckImg() {
    // sysCode = "";
    var filename = empGuid + "," + empGuid + "," + empGuid + "," + empGuid;
    var funcCode = "PersonID,PersonZC,Person,PersonSign";
   
    return { "funcCode": funcCode, "filename": filename };

}
///取得未上传图片名
function GetCheckImgTitle(code) {
    var result = "";
    if (code.length > 0) {
        if (code == "Person") {
            result = $("#personimg").attr("title");
        } else {
            result = $(".corpImages img[funccode='" + code + "']").eq(0).attr("title");
        }
    }
    return result;
}
//导入资格证书
function ImportEmpTitleDetails() {
    var pageData = {};
    pageData.action = "ImportEmpCert";
    pageData.empGuid = empGuid;
    pageData.areaCode = areaCode;
    pageData.idCard = $("#txtCard").val();
    pageData.rand = Math.random();
    $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", pageData, function (data) {
        GetEmpQualities();
        GetExpertRelation(1);
    });
}

////取得固定电话
function GetTel() {
    var tel = "";
    if ($("#txtTel1").val() != "") {
        tel = $("#txtTel1").val() + "-" + $("#txtTel2").val();
    }
    if ($("#txtTel3").val() != "") {
        tel += "-" + $("#txtTel3").val();
    }
    $("#hdnTel").val(tel); 
}
////取得email
function GetEmail() {
    var email = "";
    if ($("#txtEmail1").val() != "" || $("#txtEmail2").val() != "") {
        email = $("#txtEmail1").val() + "@" + $("#txtEmail2").val();
    }
    $("#hdnEmail").val(email); 
}
/*
*保存人员基本信息
*对postExpert===1时进行的特殊操作，目的是保存时不进行数据验证
*/
function EmpInfoSave(btnId,postExpert) {
    //数据验证
    $("#hdempExtId").val(eduGuid);
    GetTel();
    GetEmail();

    if (postExpert === 1) {
        var dataValid = CheckControlValid(btnId);
        if (!dataValid) {
            return false;
        }
    }

    //取得验证图片
    var img = GetCheckImg();
    var funcCode = img.funcCode;
    var imgName = img.filename;
    //取得参数
    $("#" + tFlag).val(typeFlag);
    var pageData = {};
    pageData.empGuid = empGuid;
    pageData.areaCode = areaCode;
    pageData.corpGuid = corpGuid;
    var dataStr = GetData(btnId).replace("尚未取得",""); //取得页面上的所有数据
    pageData.data = dataStr;
    pageData.rand = Math.random();
    
    if (funcCode.length > 0 && postExpert === 1) {
        pageData.funcCode = funcCode;
        pageData.filename = imgName;
    }
    //提交
    $("#" + btnId).attr("disabled", "disabled");
    if (status == "0") {
        pageData.action = "EmpInfoAdd";
        EmpInfoAdd(pageData, btnId);
    } else {
        pageData.action = "EmpInfoEdit";
        EmpInfoEdit(pageData, btnId, postExpert);
    }
    ImportEmpTitleDetails();
}
/*添加人员基本信息*/
function EmpInfoAdd(pageData, btnId) {
    $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", pageData, function (data) {
        $("#" + btnId).removeAttr("disabled");
        if (data.Result) {
            var rvalue = data.ReturnValue; //操作成功返回用户信息
            empGuid = rvalue.EmpGuid;
            ok = 1;
            status = 1;

        } else {
            //未上传的图片提示
            if (data.Message == "img") {
                var text = GetCheckImgTitle(data.ReturnValue);
                OpenAlert("人员相关证件[" + text + "]必须上传！");
                return false;
            }
        }
        GetEmpUserLog(1, 10);
        OpenAlert(data.Message);
        //  returnToParent();           
    });
}

/*修改人员基本信息*/
function EmpInfoEdit(pageData, btnId, postExpert) {
    $.ajax({
        url: "../Handlers/PsnEmpInfoHandler.ashx",
        data: pageData,
        type: "post",
        cache: false,
        dataType: "json",
        success: function (data) {
            $("#" + btnId).removeAttr("disabled");
            //未上传的图片提示
            if (data.Message == "img") {
                var text = GetCheckImgTitle(data.ReturnValue);
                OpenAlert("人员相关证件[" + text + "]必须上传！");
                return false;
            }
            if (data.Result && postExpert == 1) {
                ExpertSubmit();
                return false;
            }
            GetEmpUserLog(1, 10);
            OpenAlert(data.Message);
        }
    });

}
/*上报专家信息*/
function ExpertSubmit() {

    var parmer = {};
    parmer.action = "ExpertPost";
    parmer.empGuid = empGuid;
    parmer.corpGuid = corpGuid;
    parmer.areaCode = areaCode;
    parmer.message = "人员上报";
    parmer.optType = 4;
    parmer.descr = "";
    parmer.rand = Math.random();
    $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", parmer, function (data) {

        if (data.Result) {
            OpenAlertFn(data.Message);
        } else {
            //未上传的图片提示
            if (data.Message == "img") {
                OpenAlert(data.ReturnValue);
                return false;
            }
            OpenAlert(data.Message);
        }
    });
}
/*取得人员基本信息**/
function SetEmail() {
    if ($("#hdnEmail").val() == null) {
        return;
    }
    var emails = $("#hdnEmail").val().split('@');
    if (emails.length > 1) {
        $("#txtEmail1").val(emails[0]);
        $("#txtEmail2").val(emails[1]);
    }
}
function SetTel() {
    if ($("#hdnTel").val() == null) {
        return;
    }
    var tels = $("#hdnTel").val().split('-');
    if (tels.length > 1) {
        $("#txtTel1").val(tels[0]);
        $("#txtTel2").val(tels[1]);
    }
    if (tels.length == 3) {
        $("#txtTel3").val(tels[2]);
    }
}
function GetStartTimeYear() {
    if ($("#txtStartTime").val().length > 4) {
        $("#txtStartTime").val($("#txtStartTime").val().substring(0,4)+"年");
    }
}
function SetDefault() {
    if ($("#txtExpertCardID").val() == "") {
        $("#txtExpertCardID").val("尚未取得");
    }
    if ($("#hdnCardBeginDate").val() != "" && $("#hdnCardBeginDate").val().length>=10) {
        $("#txtExpertCardBeginDate").val($("#hdnCardBeginDate").val().substring(0,10));
    }
    if ($("#hdnExpertCardDate").val() != "" && $("#hdnExpertCardDate").val().length >= 10) {
        $("#txtSeniorExpertCardDate").val($("#hdnExpertCardDate").val().substring(0, 10));
    }
    if ($("#hdnCardEndDate").val() != "" && $("#hdnCardEndDate").val().length >= 10) {
        $("#txtExpertCardEndDate").val($("#hdnCardEndDate").val().substring(0, 10));
    }
  
}

function GetEmpInfo() {
    $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", { "action": "EmpInfo", "empGuid": empGuid, "areaCode": areaCode, "rand": Math.random() }, function (data) {
        if (data.length == 0 || data == null) {
            OpenAlert("未查询到有效数据！");
            return false;
        }
        if (data.result == 1) {
            OpenAlert(data.message);
            return false;
        }
        var empInfo1 = data.empInfo; //基本信息
        var empPost1 = data.empPost; //职称
        var empExt1 = data.empExt; //安全考核证
        ////人员基本信息
        if (empInfo1 != null && empInfo1.length > 0) {
            for (var i = 0, j = empInfo1.length; i < j; i++) {
                SetControlVal("empInfo", empInfo1[i]); //基本信息页面控件赋值
                if (empInfo1[i].IsSeniorExpert) {
                    $("#zjZhenghao").html("资深专家证号");
                }

                SetDefault();
                SetEmail();
                SetTel();
                GetStartTimeYear();
            }
        }
        ////职称信息
        if (empPost1 != null && empPost1.length > 0) {
            for (var i = 0, j = empPost1.length; i < j; i++) {
                SetControlVal("empPost", empPost1[i]); //职称页面控件赋值
                SelChange(); //加载下拉列表
                $("#" + DropSubQual).val(empPost1[i].Post_psZGCode);
            }
        }
        //安全考核证
        if (empExt1 != null && empExt1.length > 0) {
            for (var i = 0, j = empExt1.length; i < j; i++) {
                SetControlVal("empExt", empExt1[i]); //安全考核证页面控件赋值
                //安全考核证guid用于上传图片
                if ($("#hdempExtId").val() != "00000000-0000-0000-0000-000000000000") {
                    eduGuid = $("#hdempExtId").val(); //赋值安全考核证guid
                }
            }
        }
        //加载图片事件
        ImgCardShow("");
        PersonKHImgs(eduGuid); //安全考核证图片

        if ($("#txtCard").val()) {
            IDCardCheck();
        }
    });
    //人员头像
    ImgShow();
}


/*加载日志数据*/
function GetEmpUserLog(pageNo, pageSize) {
    var pageData = {};
    pageData.action = "UserLog";
    pageData.empGuid = empGuid;
    pageData.pageNo = pageNo;
    pageData.pageSize = pageSize;
    pageData.areaCode = areaCode,
    pageData.userRole = userRole;
    pageData.rand = Math.random();
    $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", pageData, function (data) {
        var innerHTML = "";
        $("#EmpLogs").empty();
        $("#list_page").empty();
        var items = data.data;
        allCount = data.pageCount;
        var IsrtDate = "";
        if (items != null && items.length > 0) {
            
            ShowLastFlowStr(items[0]);

            for (var i = 0, j = items.length; i < j; i++) {
                var item = items[i];
                if (item.IsrtDate != null && item.IsrtDate.length > 10) {
                    IsrtDate = item.IsrtDate.replace("T", " ");
                } else {
                    IsrtDate = item.IsrtDate;
                }
                innerHTML += ' <tr><td>' + item.IsrtUserName + '</td><td>' + item.Content + '</td><td>' + IsrtDate + '</td><tr>';
            }
        }
        $("#EmpLogs").append(innerHTML);
        //分页
        if (allCount > pageSize) {
            var allNo = 0;
            if (allCount > 0 && pageSize > 0) {
                allNo = parseInt(allCount / pageSize);
                if (allCount % pageSize > 0) {
                    allNo++;
                }
            }
            $("#list_page").pager({
                "amount": allCount,
                "allNo": allNo,
                "pageNo": pageNo,
                "pageSize": pageSize,
                "callback": function (n) { GetEmpUserLog(n, pageSize); }
            });
        }

    });
}

////把最新审核状态显示到顶部
function ShowLastFlowStr(item) {
    if (userRole != "Expert") return;
    var content = item["Content"];
    var lblLastFlow = $("#lblLastFlow");
    var rst = "";
    if (content.match(/(.*)(审核通过|审核)((?=<)|$)/)) {
        rst = "最新通知：   您上报的信息已被" + content.match(/(.*)(审核通过|审核)((?=<)|$)/)[1] + "审核通过";
    } else if (content.match(/(.*)退回((?=<)|$)/)) {
        rst = "最新通知：   您上报的信息已被退回，请完善后重新上报";
    }
    lblLastFlow.text(rst);
}

/*加载工作经历数据*/
function GetEmpWorkExperience() {
    $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", { "action": "Experience", "empGuid": empGuid, "areaCode": areaCode, "rand": Math.random() }, function (data) {
        var innerHTML = "";
        $("#EmpWork").empty();
        if (data != null && data.length > 0) {
            var BeginDate = "";
            var EndDate = "";
            for (var i = 0, j = data.length; i < j; i++) {
                var item = data[i];
                //日期格式化
                if (item.BeginDate != null && item.BeginDate.length > 10) {
                    BeginDate = item.BeginDate.substring(0, item.BeginDate.toString().lastIndexOf('-'));
                } else {
                    BeginDate = item.BeginDate;
                }
                //日期格式化
                if (item.EndDate != null && item.EndDate.length > 6) {
                    if (item.EndDate.length >= item.EndDate.toString().indexOf('-') + 3) {
                        EndDate = item.EndDate.substring(0, item.EndDate.toString().indexOf('-') + 3);
                    } else {
                        EndDate = item.EndDate;
                    }
                } else {
                    EndDate = item.EndDate;
                }
                innerHTML += ' <tr><td><input  type="checkbox" id="' + item.ID + '" entity="' + item.CorpName + '"/></td>';
                innerHTML += '<td>' + (i + 1).toString() + '</td><td>' + BeginDate + '</td><td>' + EndDate + '</td><td>' + item.CorpName + '</td> <td>' + item.Post + '</td></tr>';
            }
        }
        $("#EmpWork").append(innerHTML);
    });
}

/*加载专家专业数据*/
function GetExpertSpeciality(isMain) {
    $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", { "action": "Expert", "empGuid": empGuid, "areaCode": areaCode, "isMain": isMain, "rand": Math.random() }, function (data) {
        var innerHTML = "";
        var innerHTML2 = "";
        if (isMain == true) {
            $("#ExpSpecMain").empty();
            $("#ContentPlaceHolder1_UCPsnExpertInfo1_mainSpecBtnDiv").hide();
        }
        else {
            $("#ExpSpecEtc").empty();
            $("#ContentPlaceHolder1_UCPsnExpertInfo1_etcSpecBtnDiv").hide();
            $("#ExpSpecEtc2").empty();
            $("#ContentPlaceHolder1_UCPsnExpertInfo1_etcSpecBtnDiv2").hide();
        }
        if (data != null && data.length > 1) {
            var item = data[0];
            innerHTML2 += ' <td height="28" style="display:none"><input  type="checkbox" checked="checked"  id="' + item.SpecialityGuid + '"/></td>';
            innerHTML2 += '<td height="28">' + item.SpecialityName + '</td>';
            var item2 = data[1];
            innerHTML += ' <td height="28" style="display:none"><input  type="checkbox" checked="checked"  id="' + item2.SpecialityGuid + '"/></td>';
            innerHTML += '<td height="28">' + item2.SpecialityName + '</td>';
            $("#ExpSpecEtc2").append(innerHTML2);
            if (innerHTML2 != "") {
                $("#ContentPlaceHolder1_UCPsnExpertInfo1_etcSpecBtnDiv2").show();
            }
            else {
                innerHTML2 = '<td height="28"></td>';
                $("#ExpSpecEtc2").append(innerHTML2);
            }
        }
        else if (data != null && data.length > 0) {
            var item = data[0];
            innerHTML += ' <td height="28" style="display:none"><input  type="checkbox" checked="checked"  id="' + item.SpecialityGuid + '"/></td>';
            innerHTML += '<td height="28">' + item.SpecialityName + '</td>';
            if (isMain == false) {
                innerHTML2 = '<td height="28"></td>';
                $("#ExpSpecEtc2").append(innerHTML2);
            }

        }
        if (isMain == true) {
            $("#ExpSpecMain").append(innerHTML);
            if (innerHTML != "") {
                $("#ContentPlaceHolder1_UCPsnExpertInfo1_mainSpecBtnDiv").show();
            }
            else {
                innerHTML = '<td height="28"></td>';
                $("#ExpSpecMain").append(innerHTML);
            }
        }
        else {
            $("#ExpSpecEtc").append(innerHTML);
            if (innerHTML != "") {
                $("#ContentPlaceHolder1_UCPsnExpertInfo1_etcSpecBtnDiv").show();
            }
            else {
                innerHTML = '<td height="28"></td>';
                $("#ExpSpecEtc").append(innerHTML);
            }
            if (!innerHTML2) {
                innerHTML2 = '<td height="28"></td>';
                $("#ExpSpecEtc2").append(innerHTML2);
            }
        }
    });
}

/*加载专家专关系数据*/
function GetExpertRelation(flag) {
    $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", { "action": "Relation", "empGuid": empGuid, "areaCode": areaCode, "flag": flag, "rand": Math.random() }, function (data) {
        var innerHTML = "";
        if (flag == "1") {
            $("#CorpRelBody").empty();
        }
        else {
            $("#ExpRelBody").empty();
        }
        if (data != null && data.length > 0) {
            for (var i = 0, j = data.length; i < j; i++) {
                var item = data[i];
                item.Reason=item.Reason == null ? "" : item.Reason;
                innerHTML += ' <tr><td><input  type="checkbox" id="' + item.Gid + '"/></td>';
                innerHTML += '<td>' + item.EntityName + '<td>' + item.Reason + '</td></tr>';
            }
        }
        if (flag == "1") {
            $("#CorpRelBody").append(innerHTML);
        }
        else {
            $("#ExpRelBody").append(innerHTML);
        }
    });
}

/*加载人员资格证书数据*/
function GetEmpQualities() {
    $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", { "action": "Qualitie", "empGuid": empGuid, "areaCode": areaCode, "type": manual, "isValid": "100", "rand": Math.random() }, function (data) {
        var innerHTML = "";
        $("#EmpQualities").empty();
        if (data != null && data.length > 0) {
            var GetCertificateDate = "";
            var ZsEndDate = "";
            var CLCode = "";
            var RegisterCorpName = "";
            for (var i = 0, j = data.length; i < j; i++) {
                var item = data[i];
                //日期格式化
                if (item.GetCertificateDate != null && item.GetCertificateDate.length > 10) {
                    GetCertificateDate = item.GetCertificateDate.substring(0, 10);
                } else {
                    GetCertificateDate = item.GetCertificateDate == null ? "" : item.GetCertificateDate;
                }
                if (item.ZsEndDate != null && item.ZsEndDate.length > 10) {
                    ZsEndDate = item.ZsEndDate.substring(0, 10);
                } else {
                    ZsEndDate = item.ZsEndDate == null ? "" : item.ZsEndDate;
                }
                var remark = "";
                if (item.Remark != null && item.Remark.length >= 1) {
                    if (item.Remark.substring(0, 1) == "0") {
                        remark = "本人无此项注册资格";
                    }
                    if (item.Remark.substring(0, 1) == "1") {
                        remark = "本人存在此项注册资格信息有误";
                    }
                }
                if (item.CSCode != null && item.CSCode == "无") {
                    item.CSCode = "--";
                }
                //编号除null
                CLCode = item.CLCode == null ? "" : item.CLCode;
                RegisterCorpName = item.RegisterCorpName == null ? "" : item.RegisterCorpName;
                innerHTML += ' <tr><td><input  type="checkbox" id="' + item.EducationGUID + '" entity="' + RegisterCorpName + '"/></td>';
                innerHTML += '<td>' + item.CertificateName + '</td><td><a onclick="return EmpQualitiesView(\'' + item.EducationGUID + '\');" href="javascript:void(0);"><span style="color: #43a9f5">' + item.CertificateCode + '</span></a></td>';
                innerHTML += '<td>' + CLCode + '</td><td>' + item.CSCode + '</td><td>' + RegisterCorpName + '</td><td>' + GetCertificateDate + '</td><td>' + ZsEndDate + '</td><td><a onclick="return EmpCertAmendView(\'' + item.EducationGUID + '\');" href="javascript:void(0);" title="点击查看详情"><span style="color: #43a9f5">' + remark + '</span></a></td></tr>';

            }
        }
        $("#EmpQualities").append(innerHTML);

    });
}
//资格证书预览
function EmpQualitiesView(educationGUID) {
    ShowUpForm("../Person/PersonEmpCertInfo.aspx?opt=2&empGuid=" + empGuid + "&certGuid=" + educationGUID + "&manual=" + manual, 800, 650, top);
}
//显示修正备注
function EmpCertAmendView(educationGUID) {
    ShowUpForm("../Person/PersonEmpCertAmend.aspx?opt=2&empGuid=" + empGuid + "&certGuid=" + educationGUID, 650, 450, top);
}
/*加载人员执业手册数据*/
function GetEmpQualitiesSC() {
    $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", { "action": "Qualitie", "empGuid": empGuid, "isValid": "0", "type": manual, "areaCode": areaCode, "rand": Math.random() }, function (data) {
        var innerHTML = "";
        $("#EmpQualitiesSC").empty();
        $("#empUpImgDiv .empCertImg").remove();
        if (data != null && data.length > 0) {
            var GetCertificateDate = "";
            var ZsEndDate = "";
            var CLCode = "";
            var RegisterCorpName = "";
            for (var i = 0, j = data.length; i < j; i++) {
                var item = data[i];
                if (item.GetCertificateDate != null && item.GetCertificateDate.length > 10) {
                    GetCertificateDate = item.GetCertificateDate.substring(0, 10);
                } else {
                    GetCertificateDate = item.GetCertificateDate;
                }
                if (item.ZsEndDate != null && item.ZsEndDate.length > 10) {
                    ZsEndDate = item.ZsEndDate.substring(0, 10);
                } else {
                    ZsEndDate = item.ZsEndDate == null ? "" : item.ZsEndDate;
                }
                CLCode = item.CLCode == null ? "" : item.CLCode;
                RegisterCorpName = item.RegisterCorpName == null ? "" : item.RegisterCorpName;
                innerHTML += ' <tr><td><input  type="checkbox" id="' + item.EducationGUID + '" typeflag="' + item.TypeFlags + '" certCode="' + item.CertificateCode + '" entity="' + RegisterCorpName + '"/></td>';
                innerHTML += '<td>' + item.CertificateName + '</td><td><a onclick="return EmpQualitiesSCView(\'' + item.EducationGUID + '\');" href="javascript:void(0);"><span style="color: #43a9f5">' + item.CertificateCode + '</span></a></td>';
                innerHTML += '<td>' + CLCode + '</td><td>' + item.CSCode + '</td><td>' + RegisterCorpName + '</td><td>' + GetCertificateDate + '</td><td>' + ZsEndDate + '</td></tr>';
                GetEmpQualitiesImg(item.EducationGUID, item.CertificateName);
            }
        }
        $("#EmpQualitiesSC").append(innerHTML);
        EmpQualitiesShowImg();
    });
}
function EmpQualitiesSCView(educationGUID) {
    ShowUpForm("../Person/PersonEmpCertInfo.aspx?opt=2&empGuid=" + empGuid + "&certGuid=" + educationGUID + "&manual=" + manual, 800, 650);
}

//取得资格证书图片加载到人员相关图片begin
function GetEmpQualitiesImg(EducationGUID, CertificateName) {
    var html = ' <div class="corpImages empCertImg" >';
    html += '<img alt="点击查看大图" src="../images/photobg.jpg" class="pointer" width="150" height="150" funccode="PersonZG" syscode="EF" title="资格证书" imgnm="' + EducationGUID + '"/>';
    html += '<div class="corpImagesTitle"><span>' + CertificateName + '</span></div></div>';
    $("#empUpImgDiv").append(html);
}
//点击预览图片事件
function EmpQualitiesShowImg() {
    $("#empUpImgDiv .empCertImg img").each(function () {
        var sysCode = $(this).attr("syscode");
        var funcCode = $(this).attr("funccode");
        var imgname = $(this).attr("imgnm");
        var title = "";
        if ($(this).attr("title") != "undefined") {
           title = $(this).attr("title");
        }
        $(this).attr("src", "../Handlers/GetFileHandler.ashx?fileName=" + imgname + ".jpg&sysCode=" + sysCode + "&funcCode=" + funcCode + "&rand=" + Math.random());
        $(this).click(function () {
            ShowUpForm("../Enterprise/UploadFileShowList.aspx?title=" + escape(title) + "&fileName=" + imgname + "&fileType=.jpg&sysCode=" + sysCode + "&funcCode=" + funcCode, 800, 600);
        });
    });
} //end

/*人员证件图片身份证，职称，安全考核证处理*/
/*显示图片列表*/
function ShowImgList(imgObj, filename) {
    var title = imgObj.attr("title");
    if (title == "undefined") {
        title = "";
    }

    var urlParam = {
        sysCode:imgObj.attr("syscode"),
        title: title,
        filename: filename,
        FuncCode: imgObj.attr("funccode"),
        rand: Math.random(),
        isSingle: imgObj.attr("isSingle"),
        fileType:".jpg"
    };
    
    imgObj.click(function () {
        $.ligerDialog.open({ url: "../Enterprise/UploadFileShowList.aspx?" + $.param(urlParam), width: 820, height: 650, title: '', isResize: true, buttons: [{ text: '关闭', onclick: function (item, dialog) { dialog.close(); } }] });
        return false;
    });
}

/*打开图片上传窗口*/
function GetImgList(imgObj, filename) {

    var urlParam = {
        title: imgObj.attr("title"),
        filename: filename,
        FuncCode: imgObj.attr("funccode"),
        rand: Math.random(),
        isSingle: imgObj.attr("isSingle")
    };
    
    imgObj.click(function () {
        ShowUpForm("../UserControl/FileUploadList.aspx?" + $.param(urlParam), 640, 600);
        return false;
    });
}
/*显示单张图片*/
function ShowImg(imgObj) {
    var sysCode = imgObj.attr("syscode");
    var funcCode = imgObj.attr("funccode");
    var imgnm = imgObj.attr("imgnm");
    if (imgnm == "") {
        if (funcCode == "PersonKH") {
            imgnm = eduGuid;
        } else {
            imgnm = empGuid;
        }
    }
    imgObj.attr("src", "../Handlers/GetFileHandler.ashx?gettype=last&fileName=" + imgnm + ".jpg&sysCode=" + sysCode + "&funcCode=" + funcCode + "&rand=" + Math.random());
}
//身份证和职称显示事件
function EmpImgBtnClick() {
    $(".corpImages img").each(function () {
        var funcCode = $(this).attr("funccode");
        if (funcCode != "PersonKH") {
            ShowImgList($(this), empGuid);
        }
    });
    EmpImgUploadBtnClick();
}
//身份证和职称上传事件
function EmpImgUploadBtnClick() {
    $(".updloadbtn").each(function () {
        var funcCode = $(this).attr("funccode");
        if (funcCode != "PersonKH") {
            GetImgList($(this), empGuid);
        }
    });
}
/*显示头像图片*/
function ImgShow() {
    $("#personimg").attr("src", "../Handlers/GetFileHandler.ashx?gettype=last&fileName=" + empGuid + ".jpg&sysCode=EFNoWater&funcCode=Person&rand=" + Math.random());
}
/*显示相关图片小图--页面加载和上传返回更新，所相关图片事件*/
function ImgCardShow(code) {
    if (code.length > 0) {
        $(".corpImages img[funccode='" + code + "']").each(function () {
            ShowImg($(this));
        });
        return;
    }
    $(".corpImages img").each(function () {
        ShowImg($(this));
    });
}
/*身份证和职称放大镜预览图片*/
function ToImgZoom() {
    $(".imgZoom").each(function () {
        var funcCode = $(this).attr("funccode");
        if (funcCode != "PersonKH") {
            ShowImgList($(this), empGuid);
        }
    });
}
/*安全考核证图片处理*/
function PersonKHImgs(filename) {
    ShowImgList($("#PersonKHZoom"), filename); //显示
    ShowImgList($("#PersonKHImg"), filename);
    GetImgList($("#PersonKHUpImg"), filename); //上传
    GetImgList($("#PersonKHUp"), filename);
}
/*关闭窗口执行事件*/
function OnClientClose(args) {
    var arg = args;
    if (arg) {
        if (arg.Result == 1) {
            return;
        }
        var childWinName = arg.childWinName;
        switch (childWinName) {
            case "Cert": //资格证书
                GetEmpQualities();
                break;
            case "CertSC": //执业手册
                GetEmpQualitiesSC();
                GetExpertRelation(1);
                break;
            case "Cert-Expert": //专家
                GetEmpQualities();
                GetEmpQualitiesSC();
                GetExpertRelation(1);
                break;
            case "Audit":
                // window.location = window.location.href;
                returnToParent(1);
                break;
            case "Specs":
                GetExpertSpeciality(true);
                GetExpertSpeciality(false);
                break;
            case "Relation":
                GetExpertRelation(1);
                GetExpertRelation(0);
                break;
            default: //工作经历
                GetEmpWorkExperience();
                GetExpertRelation(1);
                break;
        }
    }
    GetEmpUserLog(1, 10);
}
//审核关闭事件
function OnClientClose2(args) {
    var arg = args;
    if (arg) {
        if (arg.Result == 1) {
            return;
        }
        var childWinName = arg.childWinName;
        switch (childWinName) {
            case "Audit":
                top.ChildDialogCallBack = "OnClientCloseAudit";
                top.ChildDialogClose(1);
                //                    parent.OnClientCloseAudit(1);
                //                    window.parent.$.ligerDialog.close(); ////关闭dialog
                //                    parent.$(".l-dialog,.l-window-mask").hide(); ////去除父窗体遮罩层
                break;
        }
    }
}
//图片上传关闭事件
function OnClientCloseImg(args) {
    var arg = args;
    if (arg) {
        if (arg.Result == 1) {
            return;
        }
        switch (arg.funcCode) {
            case "Person":
                ImgShow(); //头像
            default: //其他
                ImgCardShow(arg.funcCode);
                break;
        }
    }
}
//------------关闭窗口返回人员guid，名称------------------
function OnCloseChangeEmp() {
    $("#EmpbtnClose").click(function () {

        $.getJSON("../Handlers/PsnEmpInfoHandler.ashx", { "action": "EmpIsExist", "empGuid": empGuid, "areaCode": areaCode, "rand": Math.random() }, function (data) {
            var result = data.Result;
            //正常
            if (!result) {
                OpenConfirmFn("人员信息尚不存在，您确定要关闭窗口！", CloseCanCelEmpCallBackFn);
                return false;
            }
            OpenConfirmFn("您确定要关闭窗口！", CloseGetEmpCallBackFn);
        });
    });
}
//返回人员信息关闭窗口
function CloseGetEmpCallBackFn(yes) {
    if (!yes) {
        return false;
    }
    var oArg = { EmpGuid: empGuid, EmpName: $("#txtName").val() };
    window.parent.OnClientCloseGetEmp(oArg);
    CloseChildEmpWin();
}
//直接关闭窗口
function CloseCanCelEmpCallBackFn(yes) {
    if (!yes) {
        return false;
    }
    CloseChildEmpWin();
}
//end---------------------------------
//关闭子窗口事件
function CloseChildEmpWin() {
    window.parent.$.ligerDialog.close(); ////关闭dialog
    parent.$(".l-dialog,.l-window-mask").hide(); ////去除父窗体遮罩层
    parent.window.focus(); //返回焦点
}
/*打印*/
function EmpQualscPrint(tbodyname) {
    if (!EmpDelCheck(tbodyname)) {
        return false;
    }
    ///取得证书类型
    var keyId = "";
    var certCode = "";
    $("input[type='checkbox']:checked", $("#" + tbodyname)).each(function () {
        keyId += $(this).attr("typeflag") + ",";
        certCode += $(this).attr("certCode") + ",";
    });
    if (keyId != "") {
        keyId = keyId.substring(0, keyId.indexOf(","));
    }
    if (certCode != "") {
        certCode = certCode.substring(0, certCode.indexOf(","));
    }
    window.open("../Person/PersonEmpCertPrintAdd.aspx?empGuid=" + empGuid + "&typeflag=" + keyId + "&certCode=" + certCode);
    return false;
}
/*关闭窗口*/
function GetRadWindow() {
    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow;
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
    return oWindow;
}
function returnToParent() {
    if (model == 1) {
        var oWnd = GetRadWindow();
        oWnd.close();
    }
}
function returnToParent(result) {
    if (model == 1) {
        var oArg = new Object();
        oArg.Result = result;
        var oWnd = GetRadWindow();
        if (oWnd) oWnd.close(oArg);
    }
}
/*弹出提示*/
function OpenAlert(text) {
    $.ligerDialog.warn(text);
    return false;
}
function OpenAlertFn(text) {
    radalert(text, 330, 150, '提示', alertCallBackFn, null);
    return false;
}
function alertCallBackFn(arg) {
    window.location.reload();
}
function OpenConfirmFn(text, confirmCallBackFn) {
    $.ligerDialog.confirm(text, '', confirmCallBackFn);
    return false;
}
